package com.wxp.controller;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.modules.annotation.MenuMapping;


/**
 * Created by lewis on 2017/5/29.
 */
@Controller
@MenuMapping(name = "首页信息", operator = "index10", parentOperator = "larry")
public class IndexController {
	
	@RequestMapping("/")
    public String index1() {
        return "index";

    }
	
	@RequestMapping("/index")
    public String index() {
        return "index";

    }
	
    @RequestMapping("/login")
    public String login() {
        return "login";
    }
    
    @RequestMapping("/ajaxLogin")
    public Object ajaxLogin(String username,String password) {
    	 Subject subject = SecurityUtils.getSubject();
         UsernamePasswordToken token = new UsernamePasswordToken(username, password);
         try {
             subject.login(token);
             return "redirect:/index "; 
         } catch (AuthenticationException e) {
        	 return "login"; 
         }
       
    }


    @RequestMapping("/noauthorized")
    public String noauthorized(){
        return "noauthorized";
    }
    @RequestMapping("/logout")
    public String logout(){
    	Subject currentUser = SecurityUtils.getSubject();  
        currentUser.logout();  
        return "login";
    }


}
